package com.imcode.sortdemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class MemberApp {
    public static void main(String[] args) {
        List<Member> list = new ArrayList<>();
        Collections.addAll(list,
                new Member(200,"张三"),
                new Member(100,"李四"),
                new Member(20,"王五"),
                new Member(3,"赵六"),
                new Member(10,"田七")
        );
        for(Member m : list){
            System.out.println(m.getId() + " " + m.getUsername());
        }

        System.out.println("----------------------------");
        Collections.sort(list, new Comparator<Member>() {
            @Override
            public int compare(Member o1, Member o2) {
                return o1.getId()-o2.getId();
            }
        });

        for(Member m : list){
            System.out.println(m.getId() + " " + m.getUsername());
        }

        System.out.println("----------------------------");
        Collections.sort(list, new Comparator<Member>() {
            @Override
            public int compare(Member o1, Member o2) {
                return o2.getId()-o1.getId();
            }
        });

        for(Member m : list){
            System.out.println(m.getId() + " " + m.getUsername());
        }
    }
}
